home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / outsrt / outsrt.txt < prev   
Text File  |  1994-12-17  |  2KB  |  40 lines

  1. 'Supply the name of the outline control you want to sort when calling
  2. 'this routine. There must be a list box on your form named 'Sorter'
  3. 'and it must have its Sort property set to 'True'.
  4. '
  5. 'This routine will sort an outline control that has only one
  6. 'sub-level (That was all I needed.) but it can be modified to
  7. 'sort as many levels as are needed. If you do modify it to sort 
  8. 'unlimited levels, please contribute the result to the MS BASIC 
  9. 'forum
  10. '
  11. Sub SortOutline (outline As Control)
  12.  
  13. Dim X%, i%, Sep$
  14.  
  15. Sorter.Clear                ' Clear the sorter list box
  16. Sep$ = outline.PathSeparator    ' Save the existing path separator
  17. outline.PathSeparator = Chr(31)     ' Set path separator to something below space (ASCII 32)
  18. For X% = 0 To outline.ListCount - 1
  19.     Sorter.AddItem outline.FullPath(X%)     ' Add full path of items to list box
  20. Next X%
  21. outline.Clear           ' clear outline control so sorted items can be added
  22. For X% = 0 To Sorter.ListCount - 1
  23.     i% = InStr(Sorter.List(X%), Chr(31))
  24.     ' If there is a seperator then add the second path item to the outline control
  25.     If i% Then
  26.         outline.AddItem Mid$(Sorter.List(X%), i% + 1)
  27.         outline.PictureType(outline.ListCount - 1) = 2  ' make the picture a leaf
  28.     Else
  29.     ' If there is no seperator then this isa top level item
  30.         outline.ListIndex = -1      ' Set listindex so AddItem will add a top level item
  31.         outline.AddItem Sorter.List(X%)     ' add the top level item
  32.         outline.PictureType(outline.ListCount - 1) = 0      'set picture type to closed top level (PictureClosed)
  33.         ' Set ListIndex to top level control so each new item added will be a sub item to it.
  34.         outline.ListIndex = outline.ListCount - 1
  35.     End If
  36. Next
  37. outline.PathSeparator = Sep$        ' Restore previous path separator
  38.  
  39. End Sub
  40.